import axios from "axios"
import { ElNotification } from "element-plus"
import { request } from "./base"



export const getConfigItem = async<T>(configItemName: string): Promise<T> => {
    const res = (await request.get("/api/configs/get_config_item", { params: { configItemName } }))
    if (res.data == null || res.data.configItemData == null) {
        throw new Error("Config item not found")
    }
    return res.data.configItemData as T
}

export const updateConfigItem = async<T>(configItemName: string, configItemValue: T): Promise<void> => {
    const res = (await request.post("/api/configs/update_config_item", { configItemName, configItemValue }))
    if (res.status > 300) {
        throw new Error("Update config item failed")
    } else {
        ElNotification.success({
            title: "Success",
            message: "Update config item success"
        })
    }
    return
}